package com.mediacloud.app.newsmodule.activity;


import static com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig.getAppServerConfigInfo;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.media.MediaMetadata;
import android.media.session.PlaybackState;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.chinamcloud.audioserver.APSLifecycleKit;
import com.chinamcloud.audioserver.MusicEntity;
import com.chinamcloud.collect.AcquisitionManager;
import com.eventTrack.CDPTrackReportManager;
import com.lzf.easyfloat.interfaces.OnPermissionResult;
import com.lzf.easyfloat.permission.PermissionUtils;
import com.mediacloud.app.appfactory.cache.AppConfig;
import com.mediacloud.app.assembly.util.FunKt;
import com.mediacloud.app.assembly.util.Utility;
import com.mediacloud.app.assembly.views.FontResizeView;
import com.mediacloud.app.model.CommentCommitPushEvent;
import com.mediacloud.app.model.PaperFinishActivity;
import com.mediacloud.app.model.eventbus.event.LoginEvent;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.ArticleItemReciver;
import com.mediacloud.app.model.news.CatalogItem;
import com.mediacloud.app.model.news.IntegralConfig;
import com.mediacloud.app.nav2.utils.DateUtils;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.fragment.imagetext.MagazineDetailFragment;
import com.mediacloud.app.newsmodule.model.AddHistoryParamsData;
import com.mediacloud.app.newsmodule.pay.NormalPayUtil;
import com.mediacloud.app.newsmodule.pay.PaidMetas;
import com.mediacloud.app.newsmodule.pay.PayContentResultRefreshListener;
import com.mediacloud.app.newsmodule.utils.Addintegral;
import com.mediacloud.app.newsmodule.utils.CollectionController;
import com.mediacloud.app.newsmodule.utils.DisplayCutoutManager;
import com.mediacloud.app.newsmodule.utils.DomainUtil;
import com.mediacloud.app.newsmodule.utils.KillMusicUtils;
import com.mediacloud.app.newsmodule.utils.LoginUtils;
import com.mediacloud.app.newsmodule.utils.ToastUtil;
import com.mediacloud.app.newsmodule.utils.share.OnShareClickListener;
import com.mediacloud.app.newsmodule.utils.share.ShareWrap;
import com.mediacloud.app.newsmodule.view.FontResizeDialog;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig.NewsDetailStyle;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig.ServerAppConfigInfo.NavigateBarStyle;
import com.mediacloud.app.reslib.enums.TitileType;
import com.mediacloud.app.user.model.UserInfo;
import com.tencent.mmkv.MMKV;
import com.utils.UriTool;
import com.utils.read.AudioFloatManager;
import com.utils.read.ReadPlayView;
import com.yoake.media.player.XPlayer;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;

import tv.danmaku.ijk.media.player.IMediaPlayer;

@SuppressWarnings("ALL")
public class MagazineDetailActivity extends StyleSetActivity implements PayContentResultRefreshListener, FontResizeView.OnFontChangeListener {// DataInvokeCallBack<ArticleItemReciver>, ILikesNumUpdate, WebBrowser.ZoomTouchListener {


    /**
     * 保存网页里面的全部图集
     */
    FragmentManager manager;
    FragmentTransaction transaction;
    String navigate_id;
    String article_id;
    View broccoliView;
    Boolean isAutoPlay;
    //语音播报

    public ImageView readNews;
    public ReadPlayView readPlayView;

    private View spiderAuthorLayout;
    private ImageView spiderImage;
    private TextView spiderAuthor;
    public TextView spiderFollow;
    private boolean isSpider = false;
    public boolean isEpaper;
    public ShareWrap fontShare;
    long mTyReportStartTime = 0;
    long mTyReportEndTime = 0;


    private void initViewStub() {
        ViewStub vs = findViewById(R.id.vsBroccoli);
        vs.inflate();
        broccoliView = Utility.findViewById(mRootView, R.id.broccoli);
    }

//    @Override
//    protected void backHandle() {
//        Intent intent = new Intent();
//        intent.setClassName(ImageTextDetailActivity2.this, "com.mediacloud.app.nav2.AppHome21Style");
//        startActivity(intent);
//        super.backHandle();
//    }
//
//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            backHandle();
//        }
//        return false;
//    }

    protected APSLifecycleKit apsKit;
    //图文里处理起来很复杂 读稿、图文中插入了音频

    protected boolean activate = false;

    public void initReadView(String url) {
        ViewStub vsReadLayout = findViewById(R.id.vsReadLayout);
        //Android 7.1.1 未登录情况下，点击赞->强制登录返回->崩溃
        //ViewStub 二次inflate 导致崩溃异常
        if (vsReadLayout != null && vsReadLayout.getParent() != null) {
            vsReadLayout.inflate();
        }
        readNews = findViewById(R.id.readNews);
        Drawable drawable = Utility.tintDrawable(Color.parseColor(getContent_show_top_color()), ContextCompat.getDrawable(this, R.drawable.read_news_ico));
        readNews.setImageDrawable(drawable);
        readPlayView = findViewById(R.id.readView);
        readPlayView.setVisibility(View.GONE);
        readPlayView.setPaintColor(Color.parseColor(getContent_show_top_color()));
        readNews.setEnabled(false);
        apsKit = new APSLifecycleKit(this, "" + articleItem.getId(), null, new APSLifecycleKit.APSCallback() {
            @Override
            public void onBufferingUpdate(@Nullable IMediaPlayer mediaPlayer, int percent) {
                super.onBufferingUpdate(mediaPlayer, percent);
            }

            @Override
            public void onCompletion(@Nullable IMediaPlayer mediaPlayer) {
                super.onCompletion(mediaPlayer);
                if (isFinishing() || isDestroyed()) {
                    return;
                }
                readPlayView.pause();
                readPlayView.setVisibility(View.GONE);
                readNews.setVisibility(View.VISIBLE);

            }

            @Override
            public void onMetadataChanged(@Nullable MediaMetadata metadata) {
                super.onMetadataChanged(metadata);
            }

            @Override
            public void onPlaybackStateChanged(@Nullable PlaybackState state) {
                super.onPlaybackStateChanged(state);
                if (isFinishing() || isDestroyed()) {
                    return;
                }
                switch (state.getState()) {
                    case PlaybackState.STATE_NONE://无任何状态
                        readPlayView.setVisibility(View.GONE);
                        readNews.setVisibility(View.VISIBLE);
                        break;
                    case PlaybackState.STATE_STOPPED:
                    case PlaybackState.STATE_PAUSED:
                        readPlayView.pause();
                        break;
                    case PlaybackState.STATE_PLAYING:
                        readPlayView.start();
                        break;
                    case PlaybackState.STATE_SKIPPING_TO_NEXT://下一首
                        break;
                    case PlaybackState.STATE_SKIPPING_TO_PREVIOUS://上一首
                        break;
                    case PlaybackState.STATE_FAST_FORWARDING://快进
                        break;
                    case PlaybackState.STATE_REWINDING://快退
                        break;
                    case PlaybackState.STATE_ERROR:
                        ToastUtil.show(MagazineDetailActivity.this, "出错了");

                        break;
                }
            }

            @Override
            public void onPrepared(@Nullable IMediaPlayer mediaPlayer) {
                super.onPrepared(mediaPlayer);
                if (isFinishing() || isDestroyed()) {
                    return;
                }
                readPlayView.start();
                readNews.setVisibility(View.GONE);
                readPlayView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onServiceConnected(@Nullable ComponentName name, @Nullable IBinder iBinder) {
                super.onServiceConnected(name, iBinder);
                if (isFinishing() || isDestroyed()) {
                    return;
                }
                readNews.setEnabled(true);
                if (apsKit.isTaskPlaying()) {
                    activate = true;
                    MusicEntity entity = new MusicEntity("" + articleItem.getTitle(), url);
                    apsKit.setData(entity);
                }
            }

            @Override
            public void onUpdateProgress(@Nullable IMediaPlayer mediaPlayer) {
                super.onUpdateProgress(mediaPlayer);
            }
        });

        readPlayView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //这里点了之后 直接调用<播报控件>里的暂停和开始按钮
                apsKit.toggle();
            }
        });
        readNews.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                playAudioText(url);

            }
        });
        readNews.postDelayed(new Runnable() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (isAutoPlay) {
                            playAudioText(url);
                        }
                    }
                });
            }
        }, 500);

    }

    private void playAudioText(String url) {
        if (apsKit == null) {
            //若是在apsKit初始化前就有调用过，则等初始化完成后就自动播放
            isAutoPlay = true;
            return;
        }
        if (!activate) {
            activate = true;
            MusicEntity entity = new MusicEntity("" + articleItem.getTitle(), url);
            apsKit.setData(entity);
        }

        if (PermissionUtils.checkPermission(MagazineDetailActivity.this)) {
            startReadNews(true);
        } else {
            AudioFloatManager.showPermissionAsk(MagazineDetailActivity.this, new OnPermissionResult() {
                @Override
                public void permissionResult(boolean isOpen) {
                    startReadNews(isOpen);
                }
            });
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void insertAudioPlay(StopReadNewsEvent event) {
        if (isFinishing() || isDestroyed()) {
            return;
        }
        if (apsKit != null) {
            apsKit.unbindCallBacks();
        }
        activate = false;
    }

    private void startReadNews(boolean hasPerm) {
        if (apsKit == null) {
            //若是在apsKit初始化前就有调用过，则等初始化完成后就自动播放
            isAutoPlay = true;
            return;
        }
        if (hasPerm) {
            AudioFloatManager.Companion.getInstance(this).setArticle(articleItem);
            AudioFloatManager.Companion.getInstance(this).setCatalogItem(catalogItem);
            AudioFloatManager.Companion.getInstance(this).show();
        }
        apsKit.toggle();
        if (imageTextDetailFragment != null && imageTextDetailFragment.webViewInsertHandle != null) {
            XPlayer player = imageTextDetailFragment.webViewInsertHandle.videoPlayer;
            if (player != null) {
                player.pause();
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void finishActivity(PaperFinishActivity action) {
        finish();
    }

    @Override
    public void finish() {
        super.finish();
        if (apsKit != null) {
            if (!apsKit.isPlaying()) {
                KillMusicUtils.hideReadNewsWin();
            }
            apsKit = null;
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initViewStub();
        loadingView = Utility.findViewById(mRootView, R.id.mLoadingView);
        spiderAuthorLayout = findViewById(R.id.spiderAuthorLayout);
        spiderImage = findViewById(R.id.spiderImage);
        spiderAuthor = findViewById(R.id.spiderAuthor);
        spiderFollow = findViewById(R.id.spiderFollow);
        spiderAuthor.setTextColor(Color.parseColor(getContent_show_top_color()));
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        Uri uriData = getIntent().getData();
        if (uriData != null) {
            isFromH5OpenToReStart = UriTool.INSTANCE.isFromH5OpenToReStart(this, uriData);
            String articleid = uriData.getQueryParameter("articleid");
            String title = uriData.getQueryParameter("title");
            String cname = uriData.getQueryParameter("cname");
            String tag = uriData.getQueryParameter("tag");
            catalogItem = new CatalogItem();
            catalogItem.setCatname(cname);
            articleItem = new ArticleItem();
            try {
                articleItem.setTitle(title);
                if (!TextUtils.isEmpty(articleid))
                    articleItem.setId(Long.valueOf(articleid));
            } catch (Exception e) {
            }
        } else {
//            String title = getIntent().getStringExtra("title");
            article_id = getIntent().getStringExtra("article_id");
            navigate_id = getIntent().getStringExtra("navigate_id");
            catalogItem = getIntent().getParcelableExtra("catalog");
            articleItem = getIntent().getParcelableExtra("data");
        }
        isAutoPlay = getIntent().getBooleanExtra("isAutoPlay", false);

        if (catalogItem == null)
            catalogItem = new CatalogItem();
        catalogItem.setCatalog_type(getIntent().getStringExtra("category"));
        if (!TextUtils.isEmpty(navigate_id)) {
            catalogItem.setCatid(navigate_id);
        }
        if (articleItem == null) {
            articleItem = new ArticleItem();
            articleItem.setId(Long.valueOf("" + article_id));
            articleItem.setSummary(getIntent().getStringExtra("summary"));
            articleItem.setTitle(getIntent().getStringExtra("title"));
            articleItem.setUrl(getIntent().getStringExtra("url"));
            articleItem.setIsAdvertisement(getIntent().getIntExtra("isAdvertisement", 0));
            articleItem.setIsBarrage(getIntent().getIntExtra("isBarrage", 0));
            articleItem.setReferSourceID(getIntent().getStringExtra("ReferSourceID"));
            articleItem.setIsComment(getIntent().getStringExtra("isComment"));
        }


        isEpaper = getIntent().getBooleanExtra("IS_EPAPER", false);
        //		initVideoInfo();
        initViewChildren();
        onPageStart();
        getNewsData();
//        mTitlebar_MoreContainer.setVisibility(View.VISIBLE);
        fontShare.setArticleItem(articleItem);
        shareWrap.setArticleItem(articleItem);

//        setNewsTitle();
        showPageTransition();
        new DisplayCutoutManager(this).set(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES);
        //设置服务器自定义图标
        setCustomIcom();
        AudioFloatManager.Companion.getInstance(this).setOpenArticleId(articleItem.getId());
        showBottomBack(false);
        if (UserInfo.isLogin(this)) {
            judgeInteval();
        }
    }

    IntegralConfig config;
    boolean openInteval = false;//是否开启积分任务
    int timeInteval = 0;//增加积分时间（分）
    int time = 0;//累计时长

    Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {
                if (time <= timeInteval) {
                    time++;
                    handler.sendEmptyMessageDelayed(0, 1000);
                } else {
                    Addintegral.addintegral(MagazineDetailActivity.this, 45, articleItem);
                    time = 0;
                    handler.sendEmptyMessageDelayed(0, 1000);
                }
            }
        }
    };

    //判断是否开启积分和无和成长任务
    private void judgeInteval() {
        config = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.integralConfig;
        if (config != null) {
            if (config.enableList1 != null && config.enableList1.size() != 0) {
                for (int i = 0; i < config.enableList1.size(); i++) {
                    if (config.enableList1.get(i) == 45) {
                        openInteval = true;
                        timeInteval = config.book_least_duration_1;
                    }
                }
            }
        }
        time = MMKV.defaultMMKV().getInt("Magazine_Time" + UserInfo.getUserInfo(this).getUserid(), 0);
        if (time >= timeInteval) {
            time = 0;
        }
        if (openInteval && time < timeInteval) {
            handler.sendEmptyMessageDelayed(0, 1000);
        }
    }

    public void onShowTitle(boolean show) {
        if (serverAppConfigInfo.getBase() == TitileType.NEWS_TITLE) {
            if (isSpider) {
                if (show) {
                    spiderAuthorLayout.setVisibility(View.VISIBLE);
                } else {
                    spiderAuthorLayout.setVisibility(View.GONE);
                }
            } else {
                if (show) {
                    mTitlebar_name.setVisibility(View.VISIBLE);
                } else {
                    mTitlebar_name.setVisibility(View.INVISIBLE);
                }
            }
        }
    }

    protected void setNewsTitle() {
        int base = serverAppConfigInfo.getBase();
        if (base == TitileType.FRAME) {
            setFrameTypeTitle();
        } else if (base == TitileType.NAVIGATE) {
            setTitle(catalogItem != null ? catalogItem.getCatname() : "");
        } else if (base == TitileType.NEWS_TITLE) {
            mTitlebar_name.setVisibility(View.INVISIBLE);
            setTitle(articleItem != null ? articleItem.getTitle() : "");
        } else if (base == TitileType.NOTITLE) {
            setTitle("");
        }

    }

    protected boolean needLoadTopSecondBgSkin() {
        return super.subClassgetNeedTopSecondBgSkin();
    }

    protected NavigateBarStyle getNewsDetailNavigateBarStyle() {
        return getAppServerConfigInfo(this).getImgtxtNewsBar();
    }

    @Override
    public int getStatusBarColor() {
        if (imageTextDetailFragment != null && imageTextDetailFragment.isFullScreen())
            return Color.TRANSPARENT;
        return super.getStatusBarColor();
    }

    boolean isFullScreen = false;

    public int getLayoutResID() {
        return R.layout.aappfactory_activity_magazine_detail;
    }

    public MagazineDetailFragment imageTextDetailFragment;

    @Override
    protected void onSaveInstanceState(Bundle arg0) {
        //  super.onSaveInstanceState(arg0);
    }

    protected void getNewsData() {

        MagazineDetailFragment old = imageTextDetailFragment;
        imageTextDetailFragment = new MagazineDetailFragment();
        /*imageTextDetailFragment.setAmountListener(new PayAmountListener() {
            @Override
            public void amount(boolean need, String goodsId, String price) {
                if (need) {
                    DetailKitKt.initPayView(ImageTextDetailActivity2.this);
                    if (articleItem != null && !TextUtils.isEmpty(articleItem.getPay_tips())) {
                        tvPayTips.setText(articleItem.getPay_tips());
                    }
                    normalPayUtil.judgeShowPayView(articleItem);
                } else {
                    AppfacBuyEnableUtils.refresh(ImageTextDetailActivity2.this, true);
                }
            }
        });*/
        Bundle bundle = new Bundle();
        bundle.putParcelable("data", articleItem);
        bundle.putParcelable("catalog", catalogItem);
        imageTextDetailFragment.setArguments(bundle);
        try {
            manager = getSupportFragmentManager();
            transaction = manager.beginTransaction();
            transaction.replace(R.id.detailContentContainer, imageTextDetailFragment);
            if (old != null) {
                transaction.remove(old);
            }
            transaction.commitAllowingStateLoss();
        } catch (Exception e) {

        }
//        if (articleItem != null) {
//            getNewsDetail();
//        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public boolean onTouch(MotionEvent event) {
        if (isFullScreen)
            return false;
        if ("0".equals(articleItem.getIsComment())) {
            showCommentRelativeView(false);
        }
        hideInputComment();
        return false;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void ontoggleFullScreen(Boolean isFullScreen) {
        this.isFullScreen = isFullScreen;
        if (isFullScreen) {
            if (NewsDetailStyle.TopMenu.equals(serverAppConfigInfo.getContent_show())) {
                mTitileBar.setVisibility(View.GONE);
                hideInputComment();
            }
            bottomBarLayout.setVisibility(View.GONE);

            /*Window window = getWindow();
            WindowManager.LayoutParams windowLayoutParams = window.getAttributes();

            DisplayMetrics dm= new DisplayMetrics();
            window.getWindowManager().getDefaultDisplay().getMetrics(dm);
            windowLayoutParams.width = dm.widthPixels;

            window.setAttributes(windowLayoutParams);*/
        } else {
            bottomBarLayout.setVisibility(View.VISIBLE);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onLoginEvent(LoginEvent loginEvent) {
        if (isFinishing() || isDestroyed()) {
            return;
        }
        //20200117修复登录后页面不刷新导致无法更新付费状态的bug
        if (UserInfo.getUserInfo(this).isLogin()) {
            getNewsData();
        }
    }

    private void addHistory() {
        AddHistoryParamsData paramsData = new AddHistoryParamsData();
        paramsData.source = CollectionController.convertToSource(catalogItem);
        if (articleItem.getId() > 0) {
            paramsData.source_id = articleItem.getId();
        } else {
            if (!TextUtils.isEmpty(articleItem.getReferTarget())) {
                try {
                    paramsData.source_id = Long.parseLong(articleItem.getReferTarget());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        paramsData.summary = articleItem.getSummary();
        paramsData.title = articleItem.getTitle();
        paramsData.type = articleItem.getType() + "";
        paramsData.url = articleItem.getUrl();
        paramsData.logo = articleItem.getLogo();
        paramsData.publishdate_format = articleItem.getPublishdate_format();
    }

    boolean flag = true;

    // @Subscribe(threadMode = ThreadMode.MAIN)
    public void success(ArticleItemReciver data) {
        if (isFinishing() || isDestroyed()) {
            return;
        }
        if (data.state && data.articleItem != null/*&&(articleItem!=null&&articleItem.getId()==data.articleItem.getId())*/) {
            articleItem = data.articleItem;
            sendExposureEvent();
            articleItem.isMagazine = true;
            fontShare.setArticleItem(articleItem); //bottem Share
            shareWrap.setArticleItem(articleItem); //titleMore Share
            if (articleItem.getFromComponent() != 1)
//                setNewsTitle();

                if (!flag) {
                    return;
                }
            flag = false;
            articleItem = data.articleItem;
           /* readNews.postDelayed(new Runnable() {
                @Override
                public void run() {
                    addHistory();
                }
            },1000);*/
            if (imageTextDetailFragment != null) {
                imageTextDetailFragment.setUpdateTheData(articleItem);
            }
            refreshBottomStyle(articleItem, 1);
            data.articleItem.isEPaper = isEpaper;
            fontShare.init(data.articleItem, catalogItem, new OnShareClickListener() {
                @Override
                public void onSharePraiseClick() {

                }

                @Override
                public void onShareCommentClick() {

                }

                @Override
                public void onShareCollectionClick() {

                }

                @Override
                public void onTextFontClick() {
                    FontResizeDialog fontResizeDialog = new FontResizeDialog(MagazineDetailActivity.this, MagazineDetailActivity.this);
                    fontResizeDialog.show();

                }
            });
            if (articleItem.getSpider() != null) {
                FunKt.load(spiderImage, articleItem.getSpider().getUserImage());
                spiderAuthor.setText(articleItem.getSpider().getUserName());
                spiderFollow.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (FunKt.isFastClick()) {
                            imageTextDetailFragment.changeAttentionStatus();
                        }
                    }
                });
                isSpider = true;
            }
            //判断是否时惠军服务专项页


        } else {
            fault(null);
        }
    }


    public void fault(Object data) {
        if (isFinishing() || isDestroyed()) {
            return;
        }
        if (data == null) {
            showStateView(TYPE_NET_NOT_GIVE_FORCE, false);
        } else {
            showStateView(TYPE_NO_CONTENT, false);
        }
    }

    protected void initViewChildren() {


        initStateView();
        loadingView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TYPE_LOADING.equals(currentState)) {
                    showStateView(TYPE_LOADING, false);
                    getNewsData();
                }
            }
        });

        mTitlebar_name = findViewById(R.id.mTitlebar_name);


    }

    @Override
    public void closeStateView() {
        super.closeStateView();
        if (broccoliView != null) {
            broccoliView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (isFinishing() || isDestroyed()) {
                        return;
                    }
                    ObjectAnimator animation = ObjectAnimator.ofFloat(broccoliView, "alpha", 0f);
                    animation.setStartDelay(10);
                    animation.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            broccoliView.setVisibility(View.GONE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    animation.start();
                }
            }, 10);

        }
    }

    @Override
    protected void toggleTitleBar(boolean open) {
        super.toggleTitleBar(open);
        fontShare = new ShareWrap(this, false);
        fontShare.setShowFunction(true);
        if (open) {
            textSizeCtl.setImageResource(R.drawable.imagetext_more);
            textSizeCtl.setVisibility(View.GONE);
            textSizeCtl.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    fontShare.show(v);
                }
            });
        } else {
            textSizeCtl.setVisibility(View.GONE);
        }
    }

    @Override
    protected boolean openTitleBarSetting() {
        return true;
    }


    protected void hideInputComment() {
        if (isShowComment(articleItem)) {
            showCommentRelativeView(true);
        } else {
            showCommentRelativeView(false);
        }

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (requestCode == MemberActivity.REQUEST_CODE && intent != null && intent.getBooleanExtra(MemberActivity.REQUEST_KEY, false)) {
            if (normalPayUtil != null) {
                normalPayUtil.judgeShowPayView(articleItem);
            }
        }
    }


    @Override
    public void onBackPressed() {
        boolean value = imageTextDetailFragment != null && imageTextDetailFragment.onBackPressed();
        if (shareWrap.isShowing()) {
            shareWrap.dismiss();
            value = true;
        }
        if (value)
            return;
        super.onBackPressed();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        CDPTrackReportManager.getInstance().NewsContentDetailView(articleItem,(System.currentTimeMillis()-inTime)/1000);
        handler.removeCallbacksAndMessages(null);
        if (time > 0) {
            MMKV.defaultMMKV().putInt("Magazine_Time" + UserInfo.getUserInfo(this).getUserid(), time);
        }
        if (imageTextDetailFragment != null) {
            imageTextDetailFragment.clearWebView();
        }
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }

        if (articleItem != null) {
            if (imageTextDetailFragment != null) {

                try {
                    manager = getSupportFragmentManager();
                    transaction = manager.beginTransaction();
                    transaction.remove(imageTextDetailFragment);
                    transaction.commitAllowingStateLoss();
                } catch (Exception e) {
                }
            }
        }
        manager = null;
        transaction = null;

    }

    protected void intoLogin(Context context) {
        //   ToastUtil.show(context, R.string.please_login);
        LoginUtils.request_source="杂志详情";
        LoginUtils.invokeLogin(context);
    }


    /**
     * 和付费相关的
     */
    public ViewGroup paySeeMoreLayout;
    public TextView playHowMuch;
    public TextView tvVipPayHowMuch;
    public NormalPayUtil normalPayUtil;
    public TextView tvPayTips;


    /**
     * 是否是会员
     */
    public boolean isMember() {
        return false;
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (articleItem != null) {
            UserInfo info = UserInfo.getUserInfo(this);
            AcquisitionManager.getInstance().readEnter(info, "" + articleItem.getId(),
                    DomainUtil.getDomain(articleItem.getUrl()), articleItem.getUrl(), articleItem.getTitle(), articleItem.getContent());
        }

    }

    @Override
    protected void onStop() {
        super.onStop();
        if (articleItem != null) {
            UserInfo info = UserInfo.getUserInfo(this);
            AcquisitionManager.getInstance().readExit(info, "" + articleItem.getId(),
                    DomainUtil.getDomain(articleItem.getUrl()), articleItem.getUrl(), articleItem.getTitle(), articleItem.getContent());
        }

    }

    @Override
    public void refreshNewPayResultContent(@NotNull PaidMetas paidMetas) {
        imageTextDetailFragment.updateBuyContent(paidMetas);
        imageTextDetailFragment.showHTMLData(paidMetas.getContent());
        imageTextDetailFragment.initReadNews();
    }

    int lastLevel = -1;

    @Override
    public void onFontChange(int levelIndex) {
        if (levelIndex == lastLevel) {
            return;
        }
        lastLevel = levelIndex;
        if (imageTextDetailFragment != null) {
            int zoom = AppConfig.zoomSize.get(levelIndex);
            imageTextDetailFragment.resizeFont(levelIndex, zoom);
        }
    }

    //    @Override
//    public void onComment(@NonNull String content, String beReplayUserName, String beReplayUserId) {
//        super.onComment(content, beReplayUserName, beReplayUserId);
//        ReportManager.getInstance().news_submit_comment(articleItem.getId() + "", articleItem.getTitle(), content);
//    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    private void commentCommitPush(CommentCommitPushEvent data) {

    }
}